#ifndef NP_CONFIG_STRUCTURES_H
#define NP_CONFIG_STRUCTURES_H

#include <string>
#include <map>
#include <vector>
#include <boost/regex.hpp>

namespace configInfo
{
typedef struct ConfigInfoStruct
{
  int isactive;                         /*<是否启用>*/
  int sort;                               /*<配置文件序号>*/
  std::string flag;                          /*<唯一标记>*/
  std::string domain;                    /*<mover预留字段>*/
  std::string targetdomain;          /*<mover预留字段>*/
  std::string webname;                /*<mover预留字段>*/
  std::string charset;                     /*<编码，可能为mover预留字段>*/
  std::string indexurl;                  /*<mover预留字段>*/
  std::string filepath;                    /*<mover预留字段>*/
  std::string connstring;               /*<数据库连接字符串>*/
  std::string targetconnstring;     /*<mover预留字段>*/
  int sleeptimes;                    /*<每config休眠时间(毫秒)>*/
  int sleepbook;                    /*<每本书休眠时间(毫秒)>*/
  int sleepchapter;                /*<每章节休眠时间(毫秒)>*/
  int repeatmax;                    /*<最大重复次数，如果发现采集的小说重复次数大于此，判定后面的已经采集过>*/
  std::string lastupdate;               /*<上次循环更新到的时间>*/
  std::string doclastupdate;         /*<mover预留字段>*/
  int imagemaxwidth;          /*<mover预留字段>*/
  std::string sourceflag;              /*<mover预留字段,js调用或copy直接复制txt>*/
  std::string sourcefilepath;       /*<mover预留字段>*/
  std::string ruleflag;                  /*<规则文件标记>*/
  std::string secondrules ;         /*"ranwen;17k" in order*/
  int  maxpage  ;                 /*目标站的页数*/
  ConfigInfoStruct()
  {
    sort =0;
    flag = "";
    domain = "";
    targetdomain = "";
    webname = "";
    charset = "";
    indexurl = "";
    filepath = "";
    connstring = "";
    targetconnstring = "";
    sleeptimes = 0;
    sleepbook = 0;
    sleepchapter = 0;
    repeatmax = 0;
    lastupdate = "";
    doclastupdate = "";
    imagemaxwidth = 0;
    sourceflag = "";
    sourcefilepath = "";
    ruleflag = "";
    secondrules = "";
    maxpage =0;
  }
}ConfigInfo;
}

namespace ruleconfiguration
{
/**
  * 每个规则有下列几个选项
  */
typedef struct RegexInfoStruct
{
  std::string FilterPattern;
  std::string Method ;
  boost::regex_constants::match_flag_type Options;
  std::string Pattern ;
  //  std::string RegexName;

  RegexInfoStruct()
  {
    FilterPattern = "";
    Method = "";
    Options = static_cast<boost::regex_constants::match_flag_type>(0);
    Pattern = "";
  }
}RegexInfo;

/**
  * 一个规则文件由多个条目(RuleConfigInfo)的规则组成
  * key 为条目的名字，value 为规则信息
  */
typedef std::map<std::string, RegexInfo*> RuleConfigInfo;
typedef RuleConfigInfo::iterator RuleConfigInfoIterator;
void destoryRulConfigInfo(RuleConfigInfo& rulConfInfo);

//typedef struct ruleConfigInfo
//{
//  RegexInfo GetSiteCharset;
//  RegexInfo GetSiteName;
//  RegexInfo GetSiteUrl;
//  RegexInfo LagerSort;
//  RegexInfo NovelAuthor;
//  RegexInfo NovelCover;
//  RegexInfo NovelDefaultCoverUrl;
//  RegexInfo NovelDegree;
//  RegexInfo NovelErr;
//  RegexInfo NovelInfo_GetNovelPubKey;
//  RegexInfo NovelIntro;
//  RegexInfo NovelKeyword;
//  RegexInfo NovelList_GetNovelKey;
//  RegexInfo NovelListUrl;
//  RegexInfo NovelName;
//  RegexInfo NovelSearch_GetNovelKey;
//  RegexInfo NovelSearchData;
//  RegexInfo NovelSearchUrl;
//  RegexInfo NovelUrl;
//  RegexInfo PubChapter_GetChapterKey;
//  RegexInfo PubChapterName;
//  RegexInfo PubContent_GetTextKey;
//  RegexInfo PubContentErr;
//  RegexInfo PubContentImages;
//  RegexInfo PubContentReplace;
//  RegexInfo PubContentText;
//  RegexInfo PubContentUrl;
//  RegexInfo PubCookies;
//  RegexInfo PubIndexErr;
//  RegexInfo PubIndexUrl;
//  RegexInfo PubTextUrl;
//  RegexInfo PubVolumeContent;
//  RegexInfo PubVolumeName;
//  RegexInfo PubVolumeSplit;
//  RegexInfo RuleID;
//  RegexInfo RuleVersion;
//  RegexInfo SmallSort;
//}RuleConfigInfo;
}

namespace articleInfo
{
typedef struct ArticleInfoStruct
{
  std::string articleid;
  std::string siteid;
  std::string postdate;
  std::string lastupdate;
  std::string articlename;
  std::string keywords;
  char initial;
  std::string authorid;
  std::string author;
  std::string posterid;
  std::string poster;
  std::string agentid;
  std::string agent;
  std::string sortid;
  std::string ctypeid;          //原本为typeid
  std::string intro;
  std::string notice;
  std::string setting;
  std::string lastvolumeid;
  std::string lastvolume;
  std::string lastchapterid;
  std::string lastchapter;
  std::string chapters;
  std::string size;
  std::string lastvisit;
  std::string dayvisit;
  std::string weekvisit;
  std::string monthvisit;
  std::string allvisit;
  std::string lastvote;
  std::string dayvote;
  std::string weekvote;
  std::string monthvote;
  std::string allvote;
  std::string vipvotetime;
  std::string vipvotenow;
  std::string vipvotepreview;
  std::string goodnum;
  std::string badnum;
  std::string toptime;
  std::string saleprice;
  std::string salenum;
  std::string totalcost;
  char articletype;
  char permission;
  char firstflag;
  char fullflag;
  char imgflag;
  char power;
  char display;
  std::string downloadlink;
  std::string sortname;
  std::string cover;               /*<小说封面,数据库无该字段，为数据处理存储>*/
  std::string contentsLink;    /*<小说目录页连接，数据库无该字段>*/

  ArticleInfoStruct()
  {
    articleid = "";
    siteid = "";
    postdate = "";
    lastupdate = "";
    articlename = "";
    keywords = "";
    initial = ' ';
    authorid = "";
    author = "";
    posterid = "";
    poster = "";
    agentid = "";
    agent = "";
    sortid = "";
    ctypeid = "";          //原本为typeid
    intro = "";
    notice = "";
    setting = "";
    lastvolumeid = "";
    lastvolume = "";
    lastchapterid = "";
    lastchapter = "";
    chapters = "";
    size = "";
    lastvisit = "";
    dayvisit = "";
    weekvisit = "";
    monthvisit = "";
    allvisit = "";
    lastvote = "";
    dayvote = "";
    weekvote = "";
    monthvote = "";
    allvote = "";
    vipvotetime = "";
    vipvotenow = "";
    vipvotepreview = "";
    goodnum = "";
    badnum = "";
    toptime = "";
    saleprice = "";
    salenum = "";
    totalcost = "";
    articletype = ' ';
    permission = ' ';
    firstflag = ' ';
    fullflag = ' ';
    imgflag = ' ';
    power = ' ';
    display = ' ';
    downloadlink = "";
    sortname = "";
    cover = "";               /*<小说封面,数据库无该字段，为数据处理存储>*/
    contentsLink = "";    /*<小说目录页连接，数据库无该字段>*/
  }
}ArticleInfo;

enum COL_INDEX_ARTICLE
{
  articleid,
  siteid,
  postdate,
  lastupdate,
  articlename,
  keywords,
  initial,
  authorid,
  author,
  posterid,
  poster,
  agentid,
  agent,
  sortid,
  ctypeid,        //原本为typeid
  intro,
  notice,
  setting,
  lastvolumeid,
  lastvolume,
  lastchapterid,
  lastchapter,
  chapters,
  size,
  lastvisit,
  dayvisit,
  weekvisit,
  monthvisit,
  allvisit,
  lastvote,
  dayvote,
  weekvote,
  monthvote,
  allvote,
  vipvotetime,
  vipvotenow,
  vipvotepreview,
  goodnum,
  badnum,
  toptime,
  saleprice,
  salenum,
  totalcost,
  articletype,
  permission,
  firstflag,
  fullflag,
  imgflag,
  power,
  display,
  downloadlink,
  sortname
};
}

namespace chapterInfo
{
typedef struct ChapterInfoStruct
{
  std::string chapterid;                /*<章节ID>*/
  std::string siteid;
  std::string articleid;                   /*<小说ID>*/
  std::string articlename;             /*<小说ID>*/
  std::string volumeid;                /*<卷ID>*/
  std::string posterid;                  /*<发布者ID>*/
  std::string poster;                      /*<发布者>*/
  std::string postdate;                  /*<发布日期>*/
  std::string lastupdate;              /*<最后更新日期>*/
  std::string chaptername;         /*<章节名称>*/
  std::string chapterorder;          /*<章节序号>*/
  std::string size;                          /*<章节字数.暂不处理>*/
  std::string saleprice;
  std::string salenum;
  std::string totalcost;
  std::string attachment;              /*<附件?>*/
  char isvip;
  char chaptertype;               /*<类型：章节为0/卷为1>*/
  char power;
  char display;                       /*<是否显示>*/
  char isnew;
  std::string txtlink;                       /*<TXT链接,mover预留>*/
  std::string preview_page;          /*<上一章节,mover预留>*/
  std::string next_page;                /*<下一章节,mover预留>*/
  std::string ctype;                         /*<类型?,mover预留  图片1或文字0>*/
  std::string sourcearticleid;         /*<源站的小说ID,mover预留>*/
  std::string sourcechapterid;       /*<源站的章节ID,mover预留>*/
  std::string contentsLink;    /*<小说章节页连接，数据库无该字段>*/

  ChapterInfoStruct()
  {
    chapterid = "";                /*<章节ID>*/
    siteid = "";
    articleid = "";                   /*<小说ID>*/
    articlename = "";             /*<小说ID>*/
    volumeid = "";                /*<卷ID>*/
    posterid = "";                  /*<发布者ID>*/
    poster = "";                      /*<发布者>*/
    postdate = "";                  /*<发布日期>*/
    lastupdate = "";              /*<最后更新日期>*/
    chaptername = "";         /*<章节名称>*/
    chapterorder = "";          /*<章节序号>*/
    size = "";                          /*<章节字数.暂不处理>*/
    saleprice = "";
    salenum = "";
    totalcost = "";
    attachment = "";              /*<附件?>*/
    isvip = ' ';
    chaptertype = ' ';               /*<类型：章节为0/卷为1>*/
    power = ' ';
    display = ' ';                       /*<是否显示>*/
    isnew = ' ';
    txtlink = "";                       /*<TXT链接,mover预留>*/
    preview_page = "";          /*<上一章节,mover预留>*/
    next_page = "";                /*<下一章节,mover预留>*/
    ctype = "";                         /*<类型?,mover预留>*/
    sourcearticleid = "";         /*<源站的小说ID,mover预留>*/
    sourcechapterid = "";       /*<源站的章节ID,mover预留>*/
    contentsLink = "";    /*<小说章节页连接，数据库无该字段>*/
  }
}ChapterInfo;

enum COL_INDEX_CHAPTER
{
  chapter_chapterid,
  chapter_siteid,
  chapter_articleid,
  chapter_articlename,
  chapter_volumeid,
  chapter_posterid,
  chapter_poster,
  chapter_postdate,
  chapter_lastupdate,
  chapter_chaptername,
  chapter_chapterorder,
  chapter_size,
  chapter_saleprice,
  chapter_salenum,
  chapter_totalcost,
  chapter_attachment,
  chapter_isvip,
  chapter_chaptertype,
  chapter_power,
  chapter_display,
  chapter_txtlink,
  chapter_ctype,
  chapter_isnew,

  chapter_preview_page,
  chapter_next_page,
  chapter_sourcearticleid,
  chapter_sourcechapterid
};
}

namespace dbinfo
{
typedef struct DBInfoStruct
{
  std::string dbuser;
  std::string dbpasswd;
  std::string dbip;
  std::string dbname;
  int port;

  DBInfoStruct()
  {
    dbuser = "";
    dbpasswd = "";
    dbip = "";
    dbname = "";
    port = 0;
  }
}DBInfo;
}

namespace attachInfo
{
typedef struct AttachInfoStruct
{
  std::string attachid;
  std::string articleid;
  std::string chapterid;
  std:: string cname;
  std::string cclass;
  std::string postfix;
  std::string csize;
  std::string hits;
  std::string needexp;
  std::string uptime;
  std::string isactive;
  std::string imagelink;
  AttachInfoStruct()
  {
    attachid="";
    articleid="";
    chapterid="";
    cname="";
    postfix="";
    csize="";
    hits="";
    needexp="";
    uptime ="";
    isactive="";
    imagelink="";
  }
}AttachInfo;

enum COL_INDEX_ATTACH
{
  attach_attachid,
  attach_articleid,
  attach_chapterid,
  attach_name,
  attach_class,
  attach_postfix,
  attach_size,
  attach_hits,
  attach_needexp,
  attach_uptime
};
}

namespace mover
{
const int SIZE_CONFIG = 30;

const int SIZE_DOC_READ_BUFFER = 1024 * 512 ; /**<从chapter文件读取文件缓存的大小 */

const int SIZE_LOG_MSG = 1024 * 2;  /**<从chapter文件读取文件缓存的大小 */

const int SIZE_FILE_SPLIT_UNIT = 1000; /**<文件夹分割大小 */

typedef struct templateInfo
{
  std::string TempletsIndexHtml;
  std::string Templets_indexhtml;
  std::string Templets_indextop;
  std::string Templets_indexvolume;
  std::string Templets_indexchapter;
  std::string Templets_indexbottom;

  typedef std::vector<std::string> stringList;
  std::map<std::string, stringList> Templets_indexchapterlist;

  std::map<std::string, std::string> JieqiDefine;
  std::map<int,std::string> JieqiSort;
  std::map<std::string,std::string> JieqiArticleConfigs;

  std::string TempletsContent;

  std::string HtmlDir;
  std::string HtmlUrl;
  std::string TxtDir;
  std::string TxtUrl;
  std::string OpfDir;
  std::string OpfUrl;
  std::string AttachDir;
  std::string AttachUrl;

  templateInfo()
  {
    TempletsIndexHtml = "";
    Templets_indexhtml = "";
    Templets_indextop = "";
    Templets_indexvolume = "";
    Templets_indexchapter = "";
    Templets_indexbottom = "";
    Templets_indexchapterlist.clear();
    JieqiDefine.clear();
   JieqiSort.clear();
    JieqiArticleConfigs.clear();
    TempletsContent = "";

    HtmlDir = "";
    HtmlUrl = "";
    TxtDir = "";
    TxtUrl = "";
    OpfDir = "";
    OpfUrl = "";
    AttachDir = "";
    AttachUrl = "";
  }
}TemplateInfo;

typedef struct _webinfo
{
  std::string charset;
  std::string siteName;
  std::string temBookReader;
  std::string temChapter;
  std::string localUrl;
  std::string modulesArticleUrl;
  std::string url;
}WebInfo;

typedef struct _sourcewebsite
{
  int IsActive;
  int Sort;
  char Flag[30];
  char Domain[50];
  int Page;
  //int RepeatMax;
  int SleepTimes;
  int SleepBook;
  int SleepChapter;
}SourceWebsite;


#define OPF_PACKAGE "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"\
  "<package unique-identifier=\"http:///-2\">%s%s%s</package>"

#define OPF_META_DATA "<metadata>"\
  "<dc-metadata>"\
  "<dc:Title>%s</dc:Title><dc:Creator>%s</dc:Creator><dc:Subject></dc:Subject>"\
  "<dc:Description>%s</dc:Description><dc:Publisher>QR</dc:Publisher><dc:Contributorid>%s</dc:Contributorid>"\
  "<dc:Sortid>%s</dc:Sortid><dc:Typeid>%s</dc:Typeid><dc:Articletype>%c</dc:Articletype>"\
  "<dc:Permission>%c</dc:Permission><dc:Firstflag>%c</dc:Firstflag><dc:Fullflag>%c</dc:Fullflag>"\
  "<dc:Imgflag>%c</dc:Imgflag><dc:Power>%c</dc:Power><dc:Display>%c</dc:Display>"\
  "<dc:Date>%s</dc:Date><dc:Type>Text</dc:Type><dc:Format>text</dc:Format>"\
  "<dc:Language>ZH</dc:Language>"\
  "</dc-metadata>"\
  "</metadata>"

#define OPF_ITEM "<item id=\"%s\" href=\"%s.txt\" media-type=\"text/html\" content-type=\"chapter\" />"

#define OPF_ITEMREF "<itemref idref=\"%s\" />"

#define OPF_MANIFEST "<manifest>%s</manifest>"

#define OPF_SPINE "<spline></spline>"

#define OPF_SIZE 1024*128

#define CONTENT_SIZE 1024*1024

const int SIZE_ARTICLE_LIST = 10000;    /**<article数组长度 */

const int SIZE_CHAPTER_LIST = 20000;    /**<chapter数组长度 */

typedef struct _opfinfo
{
  char metadata[OPF_SIZE * 4];
  char mainfest[OPF_SIZE * 8];
  char spine[OPF_SIZE * 4];
}OpfInfo;
}

namespace compar
{
  typedef struct RankInfoStruct
  {
    std::string key;
    int remainTotal;
    RankInfoStruct()
    {
      key="";
      remainTotal=0;
    }
  }RankInfo;
  typedef std::map<std::string, compar::RankInfo*> typeRank;
}
#endif // NP_CONFIG_STRUCTURES_H
